package springbootorderrabbitmqproducer.demo.config;

/**
 * @ClassName TopicMqConfiguration
 * @Date 2021/6/8 0008 上午 9:48
 * @Author Administrator
 * @Description TODO
 * Version 1.0
 */

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.*;

/**
 * topic 模式
 */
@Configuration
public class TopicMqConfiguration {

    /**
     * 交换机名字
     */
    String exchangeName = "topic_eat_exchange";
    /**
     * 队列名
     */
    String smsTopicQueueName = "sms_topic_queue";
    String weChatTopicQueueName = "weChat_topic_queue";
    String emailTopicQueueName = "email_topic_queue";

    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(exchangeName,true,false);
    }


    @Bean
    public Queue smsTopicQueue(){
        return new Queue(smsTopicQueueName,true);
    }
    @Bean
    public Queue weChatTopicQueue(){
        return new Queue(weChatTopicQueueName,true);
    }
    @Bean
    public Queue emailTopicQueue(){
        return new Queue(emailTopicQueueName,true);
    }


    @Bean
    public Binding smsBinding() {
        return BindingBuilder.bind(smsTopicQueue()).to(topicExchange()).with("*.sms");
    }
    @Bean
    public Binding weChatBinding() {
        return BindingBuilder.bind(weChatTopicQueue()).to(topicExchange()).with("#.weChat.*");
    }
    @Bean
    public Binding emailBinding() {
        return BindingBuilder.bind(emailTopicQueue()).to(topicExchange()).with("com.#.email.#");
    }


}
